<template>
  <div>
    <header class="header">
      <div class="headertop">
        <div class="toplogo">
          <a href="#">
            <img
              src="https://consumer-res.huawei.com/etc/designs/huawei-cbg-site/clientlib-campaign-v4/common-v4/images/logo.svg"
              alt=""
            />
          </a>
        </div>
        <ul class="nav">
          <li>
            <i
              @click="SET_IS({ name: 'Search', i: 0 })"
              class="el-icon-zoom-in"
            ></i>
          </li>
          <li>
            <i
              @click="SET_IS({ name: 'Person', i: 1 })"
              class="el-icon-s-check"
            ></i>
          </li>
          <li>
            <i
              @click="SET_IS({ name: 'Product', i: 2 })"
              class="el-icon-s-fold"
            ></i>
          </li>
        </ul>
      </div>
      <div class="component" v-if="show">
        <transition
          :duration="{ enter: 800, leave: 100 }"
          name="custom-classes-transition"
          enter-active-class="animated fadeIn"
          leave-active-class="animated fadeOut"
        >
          <component :is="is"></component>
        </transition>
      </div>
    </header>
    <div class="banner">
      <div ref="back" class="back"></div>
    </div>
    <div class="swiper">
      <el-carousel indicator-position="outside">
        <el-carousel-item v-for="(item, index) in swiper" :key="index">
          <div class="img">
            <img :src="item.bigimg" alt="" />
            <div class="posi">
              <img :src="item.smimg" alt="" />
              <h1>{{ item.h }}</h1>
            </div>
          </div>
        </el-carousel-item>
      </el-carousel>
    </div>
  </div>
</template>

<script>
import { mapState, mapMutations } from 'vuex'
export default {
  data() {
    return {
      swiper: [
        {
          bigimg:
            'https://consumer.huawei.com/content/dam/huawei-cbg-site/greate-china/cn/mkt/homepage/mate40e/web.jpg',
          smimg:
            'https://consumer-img.huawei.com/content/dam/huawei-cbg-site/greate-china/cn/mkt/homepage/hero-banner/p50-series/p50-series.svg',
          h: '万象新声',
        },
        {
          bigimg:
            'https://consumer.huawei.com/content/dam/huawei-cbg-site/greate-china/cn/mkt/homepage/hero-banner/watch3/web.jpg',
          smimg:
            'https://consumer-img.huawei.com/content/dam/huawei-cbg-site/greate-china/cn/mkt/homepage/hero-banner/v75-s/v75.svg',
          h: '视界万象',
        },
        {
          bigimg:
            'https://consumer.huawei.com/content/dam/huawei-cbg-site/greate-china/cn/mkt/homepage/hero-banner/matepad-pro/pc-v1.jpg',
          smimg:
            'https://consumer-img.huawei.com/content/dam/huawei-cbg-site/cn/mkt/homepage/hero-banner/matebook-series/logo.svg',
          h: '无限华为',
        },
        {
          bigimg:
            'https://consumer.huawei.com/content/dam/huawei-cbg-site/cn/mkt/homepage/hero-banner/matebook-series/pc.jpg',
          smimg:
            'https://consumer-img.huawei.com/content/dam/huawei-cbg-site/greate-china/cn/mkt/homepage/hero-banner/matepad-pro/matepad-pro.svg',
          h: '创造无界',
        },
        {
          bigimg:
            'https://consumer.huawei.com/content/dam/huawei-cbg-site/greate-china/cn/mkt/homepage/hero-banner/v75-s/web.jpg',
          smimg:
            'https://consumer-img.huawei.com/content/dam/huawei-cbg-site/greate-china/cn/mkt/homepage/hero-banner/watch3/watch3.svg',
          h: '一表万象',
        },
        {
          bigimg:
            'https://consumer.huawei.com/content/dam/huawei-cbg-site/greate-china/cn/mkt/homepage/hero-banner/p50-series/web.jpg',
          smimg:
            'https://consumer-img.huawei.com/content/dam/huawei-cbg-site/common/mkt/homepage/mate40-series/cn/mate40-series/logo-0421.svg',
          h: '跃见非凡',
        },
      ],
    }
  },
  components: {
    Search: require('./page/Search.vue').default,
    Person: require('./page/Person.vue').default,
    Product: require('./page/Product.vue').default,
  },
  computed: {
    ...mapState(['is', 'show']),
  },
  methods: {
    ...mapMutations(['SET_IS']),
  },
  mounted() {
    window.onscroll = () => {
      if (document.documentElement.scrollTop <= 501) {
        this.$refs.back.style.opacity += 0.5
      }
    }
  },
}
</script>

<style lang="scss">
@import url('../../assets/animate.css');
.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
.el-carousel,
.el-carousel-item,
.el-carousel__container {
  width: 1135px !important;
  height: 501px !important;
  overflow: hidden;
}
.img img {
  width: 1135px;
  height: 501px;
}
.el-carousel__button {
  background: #000;
}
.img {
  position: relative;
}
.posi {
  position: absolute;
  top: 200px;
  left: 100px;
  text-align: left;
  img {
    height: 52px;
    width: auto;
  }
}
* {
  padding: 0;
  margin: 0;
}
a {
  text-decoration: none;
}
ul {
  list-style: none;
}
.header {
  width: 100%;
  min-height: 63px;
  padding: 13px 40px;
  background: #fff;
  position: fixed;
  box-sizing: border-box;
  border-bottom: 1px solid #ddd;
  top: 0;
  left: 0;
  z-index: 1000;
  .headertop {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .toplogo {
      img {
        width: 120px;
      }
    }
    .nav {
      display: flex;
      i {
        margin-left: 20px;
        font-size: 25px;
        cursor: pointer;
      }
    }
  }
}
.banner {
  width: 1135px;
  height: 501px;
  background: url('https://consumer.huawei.com/content/dam/huawei-cbg-site/common/mkt/homepage/live-0915/pc.jpg')
    center;
  position: fixed;
  background-size: 100%;
  top: 63px;
  left: 50%;
  margin-left: -567.5px;
  .back {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    opacity: 0;
  }
}
.swiper {
  width: 1135px;
  margin: 564px auto;
  height: 501px;
}
</style>
